class Solution(object):
    def minNumberOfFrogs(self, croakOfFrogs):
        d = {'c': 0, 'r': 0, 'o': 0, 'a': 0}
        max_len = 0
        for c in croakOfFrogs:
            if c == 'c':
                d[c] += 1
                max_len = max(max_len, d['c'])
            if c == 'r':
                d[c] += 1
                if d[c] > d['c']:
                    return -1
            if c == 'o':
                d[c] += 1
                if d[c] > d['r']:
                    return -1
            if c == 'a':
                d[c] += 1
                if d[c] > d['o']:
                    return - 1
            if c == 'k':
                if d['a'] == 0:
                    return -1
                else:
                    d['c'] -= 1
                    d['r'] -= 1
                    d['o'] -= 1
                    d['a'] -= 1
        if d['a'] > 0:
            return - 1
        return max_len
